package cn.flaty.views.web.upload;

import java.util.concurrent.Callable;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import cn.flaty.views.web.BaseController;
/**
 * 
 * servlet3.0 异步上传文件
 *
 * @author flatychen
 * @date 2014-4-21
 */
@Controller
@RequestMapping("/async")
public class AsyncUploadController extends BaseController {


	@RequestMapping(value = "/new", method = RequestMethod.GET)
	public String register() {
		return "/views/async/upload";
	}

	/**
	 * 
	 * 异步上传测试
	 * 
	 * @author flatychen
	 * @date 2014-4-20
	 * @param request
	 * @param files
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/create", method = RequestMethod.POST)
	
	public @ResponseBody Callable<String> create( HttpServletRequest request,
			@RequestParam("fileName")  MultipartFile[] files,final Model model) {
		return new Callable<String>() {
			public String call() throws Exception {
				Thread.sleep(2000);
				model.addAttribute("aa", "test");
				return "sfdfdf";
			}
		};
		
	}	

}
